﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SIOCUR.Models;

namespace SIOCUR.Controllers
{
    public class IntegratedBatchController : Controller
    {
        SIOCURRepository dbpRepository = new SIOCURRepository();

        //
        // GET: /OperatingConditions/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Registra()
        {
            return View("Registra");
        }

        [HttpPost]
        public ActionResult Registra(FormCollection formValues,INTEGRADO_DE_LOTE intlo)
        {
            String estacion = Session["sesionestacion"] as string;
            String sistema = Session["sesionsistema"] as string; 
            
            if (ModelState.IsValid)
            {
                dbpRepository.AddIntegratedBatch(estacion, sistema, Request.Form[0], Request.Form[1], DateTime.Now, Request.Form[2]);
                var intebatch = dbpRepository.FindAllIntegratedBatch().ToList();
                return View("Agregado", intebatch);
            }
            else
            {
                return View();
            }
            //return View();

        }

        public ActionResult Todos()
        {
            var intebatch = dbpRepository.FindAllIntegratedBatch().ToList();
            return View(intebatch);
        }

        public ActionResult Modifica()
        {
            String estacion = Session["sesionestacion"] as string;
            String sistema = Session["sesionsistema"] as string; 
            
            return View(dbpRepository.GetIntegratedBatchs(estacion, sistema));
        }
        
        public ActionResult Modificar(int id)
        {
            INTEGRADO_DE_LOTE il = dbpRepository.GetIntegratedBatch(id);
            return View(il);

        }

        [HttpPost]
        public ActionResult Modificar(int id, FormCollection formValues)
        {
            INTEGRADO_DE_LOTE il = dbpRepository.GetIntegratedBatch(id);
            if (TryUpdateModel(il))
            {
                dbpRepository.Save();
                return RedirectToAction("Todos");
            }
            return View("Todos");
        }

    }
}
